/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * dlgEditTelefoni.java
 *
 * Created on 1-ago-2011, 12.13.40
 */
package UI.clienti.dialogs;

import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author mrossetti
 */
public class dlgEditTelefoni extends javax.swing.JDialog {

    private JTable TabMod;
    public dlgEditTelefoni(java.awt.Frame parent, JTable Mod, boolean modal) {
        super(parent, modal);
        initComponents();
        TabMod = Mod;
        cmbTipo.removeAllItems();
        cmbTipo.addItem("");
        cmbTipo.addItem("Fisso");
        cmbTipo.addItem("Cellulare");
        cmbTipo.addItem("Fax");
        cmbTipo.setSelectedItem(TabMod.getValueAt(TabMod.getSelectedRow(), 0).toString());
        txtNum.setText(TabMod.getValueAt(TabMod.getSelectedRow(), 1).toString());
        txtRif.setText(TabMod.getValueAt(TabMod.getSelectedRow(), 2).toString());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        P = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        cmbTipo = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        txtNum = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtRif = new javax.swing.JTextField();
        cmdOk = new javax.swing.JButton();
        cmdEsci = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Gestione telefoni");

        jLabel1.setText("Tipo");

        cmbTipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Fisso", "Cellulare", "Fax" }));

        jLabel2.setText("Numero");

        jLabel3.setText("Riferimento");

        cmdOk.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/common/ok.png.png"))); // NOI18N
        cmdOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdOkActionPerformed(evt);
            }
        });

        cmdEsci.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/common/cancel.png"))); // NOI18N
        cmdEsci.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdEsciActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout PLayout = new javax.swing.GroupLayout(P);
        P.setLayout(PLayout);
        PLayout.setHorizontalGroup(
            PLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cmbTipo, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(txtNum, javax.swing.GroupLayout.DEFAULT_SIZE, 283, Short.MAX_VALUE)
                    .addComponent(jLabel3)
                    .addComponent(txtRif, javax.swing.GroupLayout.DEFAULT_SIZE, 283, Short.MAX_VALUE)
                    .addGroup(PLayout.createSequentialGroup()
                        .addComponent(cmdOk)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 165, Short.MAX_VALUE)
                        .addComponent(cmdEsci)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        PLayout.setVerticalGroup(
            PLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cmbTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtRif, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(PLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cmdOk)
                    .addComponent(cmdEsci))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        getContentPane().add(P, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cmdEsciActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdEsciActionPerformed
        if(cmbTipo.getSelectedItem().toString().equals("") && txtNum.getText().equals("") && txtRif.getText().equals("")){
            ((DefaultTableModel)TabMod.getModel()).removeRow(TabMod.getSelectedRow());
        }
        setVisible(false);
        dispose();
    }//GEN-LAST:event_cmdEsciActionPerformed

    private void cmdOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdOkActionPerformed
        if(cmbTipo.getSelectedItem().toString().equals("") && txtNum.getText().equals("") && txtRif.getText().equals("")){
            ((DefaultTableModel)TabMod.getModel()).removeRow(TabMod.getSelectedRow());
        }else{
            TabMod.setValueAt(cmbTipo.getSelectedItem().toString(), TabMod.getSelectedRow(), 0);
            TabMod.setValueAt(txtNum.getText(), TabMod.getSelectedRow(), 1);
            TabMod.setValueAt(txtRif.getText(), TabMod.getSelectedRow(), 2);
        }
        setVisible(false);
        dispose();
    }//GEN-LAST:event_cmdOkActionPerformed

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel P;
    private javax.swing.JComboBox cmbTipo;
    private javax.swing.JButton cmdEsci;
    private javax.swing.JButton cmdOk;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField txtNum;
    private javax.swing.JTextField txtRif;
    // End of variables declaration//GEN-END:variables
}
